﻿@{
    Layout = "~/Views/Shared/_level2.cshtml";
    if (false)
    {
        <script src="~/LiberUI/Scripts/jquery.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.Base.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.Action.js"></script>
        <script src="~/LiberUI/Scripts/laytpl.js"></script>
    }
}

<title>我的天联云-个人资料</title>
<link href="/SiteUI/MyBiz/Index.css" rel="stylesheet" />
@section contentnavi{
    <div id="appTitle">
        用户中心
    </div>
    <ul id="slideNavi">
        <li><a class="Lite" href="/MyBiz/Index"><i class="icon-accountcircle"></i>个人资料<i class="icon-navigatenext arrow-go"></i></a></li>
        <li><a class="Lite" href="/MyBiz/MyNavi"><i class="icon-fenlei"></i>我的应用<i class="icon-navigatenext arrow-go"></i></a></li>
        <li><a class="Lite" href="/MyBiz/MyMessage"><i class="icon-chat"></i>消息中心<i class="icon-navigatenext arrow-go"></i></a></li>
    </ul>
}
<div class="col-lg-10 col-lg-offset-1" style="display:table">
    <div class="row" id="acntSumUp">
        <div class="col-lg-2">
            <img id="userheadimg" src="~/UserFile/DefaultUserLogo.png" />
        </div>
        <div class="col-lg-5" style="padding-top:3rem">
            <span id="username"></span>&nbsp;&nbsp;<span  class="People no-certificated"></span><br />
            <a class="LinkTo" id="headImgLink" href="javascript:void(0);">修改头像</a><span>&nbsp;|&nbsp;</span><a class="LinkTo" href="/MyBiz/AlterPwd" id="btnResetPwd">修改密码</a>
        </div>
        </div>
        <div class="row infoRow">
            <div class="col-lg-3 df-title">
                手机绑定：
            </div>
            <div id="showPhone" class="col-lg-6 df-value">

            </div>
            <div class="col-lg-3 df-action">
                <a class="LinkTo" href="/MyBiz/AlterPhone">更换手机</a>
            </div>
        </div>
        @*<div class="row infoRow" ">
                <div class="col-lg-3">
                    邮箱：
                </div>
                <div class="col-lg-6">
                    gracebug@sina.com
                </div>
                <div class="col-lg-3 df-action">
                    <a class="LinkTo" href="/MyBiz/AlterMail">修改</a>
                </div>
            </div>*@
        <div class="row infoRow" >
            <div class="col-lg-3 df-title">
                实名认证：
            </div>
            <div id="realNameStatus" class="col-lg-6 df-value">
                &nbsp;
            </div>
            <div class="col-lg-3 df-action">
                <a id="realNameStatusLink" class="LinkTo" href="/MyBiz/AlterCertify">申请认证</a>
            </div>
        </div>
        <div class="row infoRow">
            <div class="col-lg-3 df-title">
                微信账号绑定：
            </div>
            <div id="wechatState" class="col-lg-6 df-value">
                未绑定|已绑定【微信昵称】
            </div>
            <div class="col-lg-3 df-action">
                <a id="wechatBind" class="LinkTo" href="/MyBiz/BindWechat">绑定</a>
            </div>
        </div>

    </div>

    <div class="col-lg-10 col-lg-offset-1 personalData" id="myCompany">
        <div class="row">
            <div class="col-lg-12 personalData_details">我的企业</div>
        </div>
        <div id="myCompanyCard">
           
        </div>
        <h6 style="margin-top:2rem"><a class="LinkTo" href="~/SetCompany.html?Company">加入/创建企业</a></h6>
        提示：只能选择一个企业设为企业名片，设为企业名片了，个人主页显示的个人企业名称为设置的企业名称。
    </div>
<script src="/LiberUI/Scripts/laytpl.js"></script>
<script id="MyCompany" type="text/html">
    <div class="row companyCard"><div class="col-lg-2"><img src="{{d.logourl}}"></div><div class="col-lg-8"><div class="col-lg-12"><h5>{{d.name}}</h5></div><div class="col-lg-12"><h5>{{(d.division)?d.division:' '}}</h5></div></div><div class="col-lg-2 " style="line-height:6rem">
       {{(d.code)?d.code:' '}}
      </div></div>
</script>
    <script>
        Index = {
            html: "",
            MyCompany: null,
            onUserReady: function () {
                $(".People").attr("objid", User.idstr);
                //头像
                $("#userheadimg").attr("src", User.headimg);
                //手机号
                $("#showPhone").vl(User.acnt);
                //姓名
                $("#username").vl((User.realname) ? User.realname : User.username);
                //实名认证
                switch (User.certifystatus) {
                    case "Pending": //审核中
                        $("#realNameStatus").vl("正在认证审核中");
                        $("#realNameStatusLink").vl("查看详情");
                        break;
                    case "Aborted": //审核不通过
                        $("#realNameStatus").vl("您的实名认证未通过审核，请重新申请");
                        break;
                    case "Completed":  //审核通过
                        $(".People").removeClass("no-certificated").addClass("certificated");
                        $("#realNameStatus").vl("您的实名认证已通过审核");
                        $("#realNameStatusLink").vl("查看详情");
                        break;
                }
                //获取与我有关的公司信息
                $.getJSON("/MyBiz/GetMyExCompanies", {}, Index.companyCard);

                //微信
                Index.wechatCard();
            },
            updateHeadImg: function (ev) {
                switch (ev.Status) {
                    case "imageLoaded":
                        $("#userheadimg").attr("src", ev.Item.thumbnail);
                        break;
                    case "uploadEnd":
                        var p = encodeURI(ev.Item.Result.path);
                        $.getJSON("/MyBiz/UpdateHeadimg", { headimg: p}, function (rtn) {
                            if (rtn.IsPositive) {
                                success("成功", "头像已修改成功");
                                User.headimg = p;
                                $("#userheadimg").attr("src", User.headimg);
                            }
                            else {
                                $("#userheadimg").attr("src", User.headimg);
                                error("失败", "没能完成修改头像操作，请稍后再试");
                            }
                        });
                        break;
                }
            },
            companyCard: function (rtn) {
                if (rtn.IsPositive) {
                    Index.MyCompany = rtn.Data;
                    var obj = {
                        name: null,
                        division:null,
                        logourl: null,
                        code:null
                    };
                    //认证公司
                    for (var i = 0; i < User.Orgs.length; i++) {
                        obj.name = User.Orgs[i].name;
                        obj.logourl = User.Orgs[i].logourl;
                        obj.division = "岗位";
                        if (i == 0) {
                            obj.code = " <div class='button disabled '>已为企业名片</div>";
                        } else {
                            obj.code = " <div class='button '>设为企业名片</div>";
                        }
                        var q = Index.tplDlvItem.render(obj);
                        $("#myCompanyCard").append(q);
                    }
                    for (var i = 0; i < Index.MyCompany.created.length; i++) {
                        obj.name = Index.MyCompany.created[i].name;
                        obj.logourl = Index.MyCompany.created[i].logourl;
                        if (Index.MyCompany.created[i].status == "Pending") {
                            obj.division = "认证申请中";
                            obj.code = null;
                        } else {
                            obj.division = "认证审核结果:不通过<br/>原因:" + Index.MyCompany.created[i].feedback;
                            obj.code = " <div class='button '>重新申请认证</div>";
                        }
                        var q = Index.tplDlvItem.render(obj);
                             $("#myCompanyCard").append(q);
                    }
                    for (var i = 0; i < Index.MyCompany.applied.length; i++) {
                        obj.name = Index.MyCompany.applied[i].name;
                        obj.logourl = Index.MyCompany.applied[i].logourl;
                        if (Index.MyCompany.applied[i].applystatus == "Pending") {
                            obj.division = "等待审批";
                            obj.code ="<div class='button '>放弃申请</div>";
                        } else {
                            obj.division = "申请被拒绝";
                            obj.code = " <div class='button '>重新申请</div>";
                        }
                        var q = Index.tplDlvItem.render(obj);
                        $("#myCompanyCard").append(q);
                    }

                }
            },
            wechatCard: function () {
                if (!User.wxname) {
                    //无绑定
                    $("#wechatState").vl("未绑定 ! 绑定微信号可实时获取重要业务信息");
                    $("#wechatBind").attr("href", "/MyBiz/BindWechat").vl("绑定");
                }
                else {
                    //有绑定
                    $("#wechatState").vl("已绑定微信号：" + User.wxname);
                    $("#wechatBind").attr("href", "#").on("click", function () {
                        $.getJSON("/MyBiz/UnbindWechat", null, function () {
                            window.history.go(0);
                        });
                    }).vl("解除绑定").show();
                }
            }
        }
        $(function () {
            $("body").on("UserReady", Index.onUserReady);
            var navis = $("#slideNavi>li");
            for (var i = 0; i < navis.length; i++) {
                if (navis.eq(i).children("a").attr("href") == window.location.pathname) {
                    navis.eq(i).children("a").addClass("current");
                    break;
                }
            }
            new LiberUI.Uploader("#headImgLink")
                        .option("FileType", "image/*")
                        .option("MaxSize", 8 * 1024 * 1024)
                        .update()
                        .on("change", Index.updateHeadImg);

            Index.tplDlvItem = laytpl($("#MyCompany")[0].innerHTML);
        })

    </script>
